/**
 * @(#) WelfareListProxy.as
 *
 * @date		2009. 02. 12.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	선택적복리 후생 포인트 내역Proxy - Proxy
 * 				선택적복리 후생 포인트 내역 조회
 */
package com.skt.common_hr.welfare.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.welfare.WelfareFacade;
	import com.skt.common_hr.welfare.model.vo.WelfareHistoryVO;
	import com.wcl.dataloader.*;
	import com.wcl.utils.DateUtil;
	import com.wcl.utils.StringUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
		
	public class popWelfareHistoryProxy extends CommonProxy
	{
		public static const NAME:String = "popWelfareHistoryProxy";
		
		public var welfareList:ArrayCollection = new ArrayCollection();
		public var itemURL:String = "";
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function popWelfareHistoryProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function historyLoad(pernr:String, year:String):void
		{
			var param:Object = new Object();
			param["I_PERNR"] 		= pernr;
			param["I_GJAHR"] 		= year;
			loadData("Z_HR_0138", param, result, fault); 
		}
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		 
		public var O_CAFBT:String = "";	
		public var O_USEBT:Number = 0;
		public var O_REMBT:Number = 0;				

		public function result(event:ResultEvent):void
		{
			if(retCode==0) {  
				O_CAFBT = StringUtil.trim(event.result["O_CAFBT"]);
//				O_USEBT = parseFloat((StringUtil.trim(event.result["O_USEBT"]));
//				O_REMBT = parseFloat(StringUtil.trim(event.result["O_REMBT"]));
				
				O_USEBT = parseFloat(event.result["O_USEBT"] );
				O_REMBT = parseFloat(event.result["O_REMBT"] );
								
				welfareList = parseUsedMoney(event.result.GT_ITAB) as ArrayCollection;				
				facade.sendNotification(WelfareFacade.LOAD_WELFARE_HISTORY_COMPLETE, this);
			}
			else {
				facade.sendNotification(WelfareFacade.LOAD_WELFARE_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			facade.sendNotification(WelfareFacade.LOAD_WELFARE_FAILED, this);
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 선택적복리후생 초기화면 list ( 상단 예산금액 )
		*/ 
		private function parseUsedMoney(srcArr:ArrayCollection):ArrayCollection
		{
			var returnArr:ArrayCollection = new ArrayCollection();	
			for each(var rec:Object in srcArr) 
			{
				var vo:WelfareHistoryVO = new WelfareHistoryVO();
				vo.GENDT 		= DateUtil.stringToDateTime(rec["GENDT"]);
				vo.GENBEG 		= DateUtil.stringToDateTime(rec["GENBEG"]);
				vo.GENEND 		= DateUtil.stringToDateTime(rec["GENEND"]);
				vo.POINT 		= int(rec["POINT"] * 10 * 10);
				vo.PERIOD 		= rec["PERIOD"];
				returnArr.addItem(vo);
			}
		
			var vo:WelfareHistoryVO = new WelfareHistoryVO();
			vo.PERIOD	= "합계";
			vo.POINT	= parseFloat(O_CAFBT) * 100;
			vo.USEBT 	= O_USEBT * 100;
			vo.REMBT 	= O_REMBT * 100;			
			returnArr.addItem(vo);		
				
			return returnArr;	
		}
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 선택적복리후생 초기화면 mainlist
		 
		private function parseWelfareList(srcArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			for each(var rec:Object in srcArr) 
			{
				var vo:WelfareVO = new WelfareVO();
				vo.GWAREKEY 	= rec["GWAREKEY"];
				vo.IDATE 		= DateUtil.stringToDateTime(rec["IDATE"]);
				vo.UDATE 		= DateUtil.stringToDateTime(rec["UDATE"]);
				vo.CAFGBN 		= rec["CAFGBN"];
				vo.CAFGTX 		= rec["CAFGTX"];
				vo.CAFTY 		= rec["CAFTY"];
				vo.CAFTX 		= rec["CAFTX"];
				vo.BNFAMT 		= int(rec["BNFAMT"] * 10 * 10);
				vo.BNKSA 		= rec["BNKSA"];
				vo.BNKTX 		= rec["BNKTX"];
				vo.DSTATUS 		= rec["DSTATUS"];
				vo.DSTATX 		= rec["DSTATX"];
				vo.BSTATUS 		= rec["BSTATUS"];
				vo.BSTATX 		= rec["BSTATX"];
				retArr.addItem(vo);
			}
			return retArr;	
		}*/
		
	}
}